
import 'package:flutter/material.dart';
import 'package:hf_enjoy/pages/house/building_list.dart';
import 'package:hf_enjoy/pages/house/house_detail.dart';
import 'package:hf_enjoy/pages/house/house_form.dart';
import 'package:hf_enjoy/pages/house/house_list.dart';
import 'package:hf_enjoy/pages/house/location_list.dart';
import 'package:hf_enjoy/pages/house/room_list.dart';
import 'package:hf_enjoy/pages/login/index.dart';
import 'package:hf_enjoy/pages/notice/index.dart';
import 'package:hf_enjoy/pages/profile/index.dart';
import 'package:hf_enjoy/pages/tab_bar_page.dart'; 
import 'package:hf_enjoy/utils/token.dart';

void main() {
  runApp(MaterialApp(
    routes: {
      '/': (context) => const TabBarPage(),
      '/detail': (context) => const NoticeDetail(),
      '/login': (context) => const LoginPage(),
    },
    onGenerateRoute: (settings) {
      final tokenManager = TokenManager();
      final token = tokenManager.getToken() ?? '';
      if (token.isEmpty && settings.name != '/login') {
        return MaterialPageRoute(builder: (context) => const LoginPage());
      }

      if (settings.name == '/profile') {
        return MaterialPageRoute(builder: (context) => ProfilePage(userInfo: settings.arguments as Map,));
      }

      if(settings.name=='/house_list'){
        return MaterialPageRoute(
          builder: (context)=>
              const HouseList()
          );
      }
      if(settings.name=='/location_list'){
        return MaterialPageRoute(
          builder: (context)=>
              const LocationList()
          );
      }
      if(settings.name=='/building_list'){
        return MaterialPageRoute(
          builder: (context)=>
               BuildingList(point: (settings.arguments as Map)['point'])
          );
      }

      if (settings.name == '/room_list') {
        Map temp = settings.arguments as Map;
        return MaterialPageRoute(builder: (context) =>  RoomList(
          point: temp['point'],
          building: temp['building'],
        ));
      }

      if(settings.name=='/house_form'){
        return MaterialPageRoute(
          builder: (context)=>
               HouseForm(params:settings.arguments as Map)
          );
      }

      if (settings.name == '/house_detail') {
        return MaterialPageRoute(
        builder: (context) => HouseDetail(id: (settings.arguments as Map)['id']));
}

      return  MaterialPageRoute(builder: (context)=>const TabBarPage());
    },
    initialRoute: '/',
  ));
}